package cn.iocoder.yudao.module.currency.service.rate;

import cn.iocoder.yudao.module.currency.config.PaymentCurrencyConfig;
import cn.iocoder.yudao.module.currency.dal.dataobject.rate.ExchangeRateDO;
import cn.iocoder.yudao.module.currency.dal.mysql.rate.ExchangeRateMapper;
import cn.iocoder.yudao.module.currency.service.rate.ExchangeRateQueryService;
import java.util.Collection;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author cai
 * @date 2024/03/05 23:55
 */
@Service
public class ExchangeRateQueryServiceImpl implements ExchangeRateQueryService {

    @Resource
    private ExchangeRateMapper exchangeRateMapper;

    @Resource
    private PaymentCurrencyConfig paymentCurrencyConfig;

    @Override
    public ExchangeRateDO getExchangeRate(String currencyCode) {
        return exchangeRateMapper.selectByCurrencyCode(currencyCode, paymentCurrencyConfig.getCode());
    }

    @Override
    public ExchangeRateDO getExchangeRate(String baseCode, String targetCode) {
        return exchangeRateMapper.selectByCurrencyCode(targetCode, baseCode);
    }

    @Override
    public List<ExchangeRateDO> getAvailableCurrencyList(String currencyName, String currencyCode, String areaName) {
        return exchangeRateMapper.selectAvailableList(currencyName, currencyCode, areaName, paymentCurrencyConfig.getCode());
    }

    @Override
    public ExchangeRateDO getPaymentCurrency() {
        return getExchangeRate(paymentCurrencyConfig.getCode());
    }

    @Override
    public List<ExchangeRateDO> getListByCode(Collection<String> currencyCodes) {
        return exchangeRateMapper.selectListByCode(currencyCodes, paymentCurrencyConfig.getCode());
    }

}
